package Servlet;

import DAO.ComplaintDAO;
import DAO.DAOFactory;
import javabean.Complaint;
import javabean.Customer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
@WebServlet("/MyComplaint")
public class MyComplaintServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession();
        Customer customer = (Customer) session.getAttribute("loginCustomer");
        ComplaintDAO complaintDAO = (ComplaintDAO) DAOFactory.getComplaintDAOInstance();
        List<Complaint> complaintList = null;
        List<Complaint> UnassignedComplaintList = null;
        try {
            UnassignedComplaintList = complaintDAO.getAllUnassignedComplaintByCustomerID(customer.getCustomerID());
            complaintList = complaintDAO.getAllComplaintByCustomerID(customer.getCustomerID());
            req.setAttribute("complaintList", complaintList);
            req.setAttribute("UnassignedComplaintList", UnassignedComplaintList);
            req.getRequestDispatcher("MyComplaint.jsp").forward(req, resp);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
